/**
 * 表格列
 */
import { ref, h } from 'vue'
import { TableColumnProps } from '../../../components/base/table/table-props'
import { Notice } from '@/entity/system/notice'
import { getFilePath } from '@/utils/file-util'
// 范围
export const NOTICE_RANGE = ['', '全部', '个人', '所有部门', '指定部门']
// 状态
export const NOTICE_STATE = ['', '暂存', '发布', '禁用']
// 类型
export const NOTICE_TYPE = ['', ' 轮播图', '公告']
export const columns: Array<TableColumnProps<Notice>> = [
  {
    title: '编号',
    customRender: ({ index }) => index + 1,
    width: 60,
    align: 'center',
  },
  {
    title: '标题',
    dataIndex: 'title',
    width: 100,
  },
  {
    title: '内容',
    dataIndex: 'content',
    width: 120,
  },
  {
    title: '封面',
    width: 100,
    dataIndex: 'cover',
    align: 'center',
    customRender: ({ record }) =>
      record?.cover
        ? h('img', {
            src: getFilePath(record?.cover),
            width: '50',
            height: '50',
          })
        : '',
  },
  {
    title: '阅读量',
    dataIndex: 'readNum',
    width: 120,
  },
  {
    title: '通知类型',
    dataIndex: 'type',
    customRender: ({ record }) => NOTICE_TYPE[record.type],
    width: 120,
  },
  {
    title: '范围',
    width: 100,
    dataIndex: 'noticeRange',
    customRender: ({ record }) => NOTICE_RANGE[record.noticeRange],
  },
  {
    title: '状态',
    width: 200,
    dataIndex: 'status',
    customRender: ({ record }) => NOTICE_STATE[record.status],
  },
  {
    title: '发布时间',
    dataIndex: 'publishTime',
    customRender: ({ record }) => (record.createTime ? record.createTime.replace('T', ' ') : ''),
    width: 200,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    customRender: ({ record }) => (record.createTime ? record.createTime.replace('T', ' ') : ''),
    width: 200,
  },
  {
    title: '修改时间',
    dataIndex: 'lastUpdateTime',
    customRender: ({ record }) => (record.lastUpdateTime ? record.lastUpdateTime.replace('T', ' ') : ''),
    width: 200,
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: 200,
    align: 'center',
    fixed: 'right',
  },
]
